import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../../util/request-util";
import {TemplateAPI} from "../../template-constants";
import {Observable} from "rxjs/Observable";
import {MsgResult} from "../../../../models/msg-result";
import {EncodeUtil} from "../../../../util/encode-util";

@Injectable()
export class TplManageService {

  constructor(
    private encodeUtil:EncodeUtil,
    private requestUtil:RequestUtil
  ) { }

  templateAdd(template):Observable<MsgResult>{
    let params = 'name='+template.name+'&useType='+template.useType+'&remark='+template.remark+'&isUse='+template.isUse
      +'&assembly='+template.assembly+'&description='+template.description
    return this.requestUtil.post(TemplateAPI.templateAdd,params);
  }

  templateDeletes(templateIds):Observable<MsgResult>{
    let params = 'templateIds=' + templateIds ;
    return this.requestUtil.post(TemplateAPI.templateDeletes,params);
  }

  getTemplateById(id):Observable<MsgResult>{
    return this.requestUtil.get(TemplateAPI.getTemplateById + '/' + id +'?format=json');
  }

  templateEdit(template):Observable<MsgResult>{
    let id= template.id;
    //serviceEdit::"id=37b6705d45d44454b391a32c1bec542e&name=ceshi004&useType=daily&remark=BJ&type=1&isUse=1&assembly=\"<!DOCTYPE html><html xmlns&description=BJ"

    let params = 'name='+template.name+'&useType='+template.useType+'&remark='+template.remark+'&type='+template.type
      +'&isUse='+template.isUse+'&assembly='+ template.assembly +'&description='+template.description;
    return this.requestUtil.put(TemplateAPI.templateEdit +'/'+ id + '?format=json' ,params);
  }

}
